//JavaScript代码区域
layui.use(['laydate','form','table'], function() {
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	
	var dtt = {}; //搜索条件
	
	initTable(dtt);
	
	laydate.render({
		elem: '#payTime',
		theme: 'molv',
		showBottom: false,
		calendar: true,
		trigger: 'click',
		value: new Date(),
		change: function(value, date){
			lay('#payTime').html(value);
		}
	});
	
	// 流水列表总览查询
	 $("#searchBtn").click(function(){
		var payStart = $('#payStart').val();
		var payEnd = $('#payEnd').val();
		var typeCode = $('#typeCode').val();
		
		dtt = {
			payStart : payStart,
			payEnd : payEnd,
			typeCode : typeCode
		}
		initTable(dtt);
	})
	
	function initTable(dtt){
		table.render({
			elem: '#account_table',
			height: 480,
			url:'/account/query/list',
			title: '流水数据列表总览',
			page: false, //开启分页
	        totalRow: false, //开启合计行
	        limit:10,
			limits: [10,20,50],
	        where: dtt,
	        method:'POST',
			cols: [ [ //表头 style="background: #79ece2"
				{field:'id', title:'id', fixed: 'left', unresize: true,hide: true},
				{field:'dayCode', title:'日常编码',  unresize: true},
				{field:'payTime', title:'支出时间',  unresize: true, templet: function(e){
					var date = new Date(e.payTime)
					return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
	      		}},
				{field:'paySumPrice', title:'支出总额',  unresize: true},
				{field:'isCompleteAccount', title:'是否对账完成',  unresize: true},
				{field:'platSource', title:'平台来源',  unresize: true},
				{field:'storeName', title:'店铺名称',  unresize: true},
				{fixed: 'right', title:'操作', toolbar: '#accountBar', width: 80,  unresize: true}
			] ],
			page: {
				layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
				groups: 5, //只显示 1 个连续页码
				first: '首页', //不显示首页
				last: '尾页', //不显示尾页
				elem:'bottomPage'
			},
			parseData: function(res){
				return {
	                "code": res.code, //解析接口状态
	                "msg": res.message, //解析提示文本
	                "count": res.count, //解析数据长度
	                "data": res.data //解析数据列表
	     	   };
			},
			response: {
  	    	    statusName: 'code' //规定数据状态的字段名称，默认：code
  	    	    ,statusCode: 0 //规定成功的状态码，默认：0
  	    	    ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
  	    	    ,countName: 'count' //规定数据总数的字段名称，默认：count
  	    	    ,dataName: 'data' //规定数据列表的字段名称，默认：data
      	  	}, 
			done: function(res){
				
			}
		});
	}
   //监听行工具事件
  table.on('tool(accountTable)', function(obj){
    var data = obj.data, //获得当前行数据
    layEvent = obj.event; //获得 lay-event 对应的值
    if(layEvent === 'detail'){
		window.open('/account/detail?pkid=' + data.pkid,'_blank');
    } 
  });
});

// 添加基本信息
function addBaseInfo(e){
	window.open('/account/add/base/info?resource=' + e,'_blank');
}
